/**
 * @description 关键利率久期概览
 * @author zls
 */
import React, { PureComponent } from 'react';
import { connect } from 'dva';
import { FirstHeaderC, XYAxisChartsC, SecondHeaderC } from '@/src/comps';

class overview extends PureComponent {
  constructor() {
    super();
    this.state = {
      data: {},
      loading: false,
    };
  }

  componentDidMount() {
    const { searchData } = this.props;

    this.getData({ ...searchData });
  }

  UNSAFE_componentWillReceiveProps(nextProps) {
    const { searchData } = this.props;
    if (JSON.stringify(nextProps.searchData) !== JSON.stringify(searchData)) {
      this.getData({ ...nextProps.searchData });
    }
  }

  //获取数据
  getData = (payload) => {
    this.setState({ data: {} });
    this.props.dispatch({
      type: 'keyRateDurationsM/getKrdSummary',
      payload: {
        ...payload,
      },
      callback: (data) => {
        this.setState({
          data: data.data,
        });
      },
    });
  };

  render() {
    const { data } = this.state;

    return (
      <div style={{ marginTop: '20px' }}>
        <SecondHeaderC title='关键利率久期概览' />
        <XYAxisChartsC series={data?.series} xAxis={data?.xAxis} height={358} dataZoom={true} type='bar' />
      </div>
    );
  }
}
export default connect(({ keyRateDurationsM, loading }) => ({
  keyRateDurationsM,
  loading: loading.effects['keyRateDurationsM/getKrdSummary'],
}))(overview);
